//
//  XYJSeeCellTextViewController.m
//  徙游记-01
//
//  Created by hcios on 2017/7/19.
//  Copyright © 2017年 鹿林. All rights reserved.
//

#import "XYJSeeCellTextViewController.h"

@interface XYJSeeCellTextViewController ()

@end

@implementation XYJSeeCellTextViewController

#pragma mark - 生命周期
-(BOOL)shouldAutorotate{
    return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor cyanColor];
    [self setupSubViews];
}



-(void)setupSubViews{
    CGFloat padding = 10;
    UILabel *viewLabel = [[UILabel alloc] init];
    viewLabel.text = _translationText;
    viewLabel.numberOfLines = 0;
    viewLabel.font = [UIFont fontWithName:FONT_NAME_LTH size:30];
    viewLabel.textAlignment = NSTextAlignmentCenter;
    CGSize topLabSize = [self sizeWithText:_translationText font:[UIFont fontWithName:FONT_NAME_LTH size:30] maxSize:CGSizeMake(SCREEN_HEIGHT - padding * 2, MAXFLOAT)];
    viewLabel.textColor = [UIColor whiteColor];
    viewLabel.backgroundColor = [UIColor clearColor];
    viewLabel.frame = RECT_MAKE(padding, SCREEN_WIDTH / 3, SCREEN_HEIGHT - padding * 2, topLabSize.height);
    [self.view addSubview:viewLabel];
}


/*
 展示的文字方法
 text 文字内容
 font 字体
 maxSize 位置
 */

-(CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize{
    NSDictionary *dict = @{NSFontAttributeName : font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
}


//横竖屏切换的方法
-(void)interfaceOrientation:(UIInterfaceOrientation)orientation{
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        SEL selector = NSSelectorFromString(@"setOrientation:");
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
        [invocation setSelector:selector];
        [invocation setTarget:[UIDevice currentDevice]];
        int val = orientation;
        //从1开始是因为0 1 两个参数已经被selector和target占用
        [invocation setArgument:&val atIndex:2];
        [invocation invoke];
    }
}



-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self dismissViewControllerAnimated:NO completion:nil];
}

@end
